package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.TopUp;
import com.lhy.vip.service.TopUpService;
import com.lhy.vip.mapper.TopUpMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【top_up】的数据库操作Service实现
* @createDate 2024-07-29 16:50:13
*/
@Service
public class TopUpServiceImpl implements TopUpService{
    @Autowired
    private TopUpMapper iTopUpMapper;

    @Override
    public List<TopUp> selectAll() {
        LambdaQueryWrapper <TopUp> lqw = new LambdaQueryWrapper<>();
        lqw.eq(TopUp::getIsDelete,0);
        return iTopUpMapper.selectList(lqw);
    }


    @Override
    public List<TopUp> selectList(TopUp iTopUp) {
        LambdaQueryWrapper <TopUp> lqw = this.lqw(iTopUp);
        return iTopUpMapper.selectList(lqw);
    }

    @Override
    public Integer insert(TopUp iTopUp) {
        return iTopUpMapper.insert(iTopUp);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                TopUp iTopUp = new TopUp();
                iTopUp.setId(Long.parseLong(id));
                iTopUp.setIsDelete(1);
                iTopUpMapper.updateById(iTopUp);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(TopUp iTopUp) {
        return iTopUpMapper.updateById(iTopUp);
    }

    @Override
    public Page<TopUp> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<TopUp>)this.selectAll();
    }

    @Override
    public Page<TopUp> pageList(TopUp iTopUp, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<TopUp>)this.selectList(iTopUp);
    }

    public LambdaQueryWrapper lqw(TopUp iTopUp){
        LambdaQueryWrapper <TopUp> lqw = new LambdaQueryWrapper<>();
        if (iTopUp.getId() != null){
            lqw.eq(TopUp::getId,iTopUp.getId());
        }
        if (iTopUp.getOrderNum() != null){
            lqw.eq(TopUp::getOrderNum,iTopUp.getOrderNum());
        }
        if (iTopUp.getMoney() != null){
            lqw.eq(TopUp::getMoney,iTopUp.getMoney());
        }
        if (iTopUp.getWay() != null){
            lqw.eq(TopUp::getWay,iTopUp.getWay());
        }
        if (iTopUp.getStatus() != null){
            lqw.eq(TopUp::getStatus,iTopUp.getStatus());
        }
        if (iTopUp.getTopTime() != null){
            lqw.eq(TopUp::getTopTime,iTopUp.getTopTime());
        }
        if (iTopUp.getPayTime() != null){
            lqw.eq(TopUp::getPayTime,iTopUp.getPayTime());
        }
        return lqw;
    }
}




